#include<bits/stdc++.h>
using namespace std;
int n,a[200210],c[200210];
random_device seed;
mt19937 rnd(seed());
int ans;
int get(){
	int sum=0;
	for(int i=1;i<n;i++){
		for(int j=i-1;j>-1;j--){
			if(c[i]^c[j]==0){
				if(a[i]==a[j])sum+=a[i];
				break;
			}
		}
	}
	return sum;
}
void SA(){
	double beginT=5000,endT=1e-10,changeT=0.9112;
	for(double i=beginT;i>endT;i*=changeT){
		int x=rnd()%n;
		c[x]^=1;
		int sum=get();
		if(sum>ans)
			ans=sum;
		else if(exp(sum-ans)*i<rnd()*1.0/INT_MAX)
			c[x]^=1;
	}
}
signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			c[i]=0;
		int crl=210;
		ans=get();
		while(crl--)SA();
		cout<<ans<<'\n';
	}
	return 0;
}
